package com.cqupt.tomwang.mixview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    private LinearLayout linearLayout;
    private int[] image = {
            R.drawable.ajax,
            R.drawable.html,
            R.drawable.java,
            R.drawable.javaee,
            R.drawable.swift
    };
    private int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        linearLayout = (LinearLayout) findViewById(R.id.root);
        //程序创建ImageView组件
        final ImageView imageView = new ImageView(this);
        //将ImageView组建添加到LinearLayout中
        linearLayout.addView(imageView);
        imageView.setImageResource(image[0]);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setImageResource(image[++count%image.length]);
            }
        });
    }
}
